<% content_for :header do %>
<div id="nav">
  <ul>
    <li><a href="/intro">活动介绍</a></li>
    <li><a href="/join" class="current">如何参与</a></li>
    <li><a href="/news">最新动态</a></li>
    <li><a href="/contact">联系我们</a></li>
  </ul>
</div>
<div id="pagetitle">
  <h1>出 行 活 动</h1>
</div>
<% end %>

<div id="content">
	<div id="innercontent">
	  <h3><%= h @tour.start_at %> 到 <%= h @tour.end_at %>，从 <%= h @tour.start_place %> 到 <%= h @tour.end_place %></h3>
		<p><em>时间：</em> <%= @tour.start_at %> 到 <%= @tour.end_at %></p>
		<p><em>出发地：</em> <%= h @tour.start_place %></p>
		<p><em>目的地：</em> <%= h @tour.end_place %></p>
		<p><em>参与人数：</em> <%= h @tour.volunteer_amount %> 人</p>
		<p><em>行程计划：</em><div style="margin-left:10px;"><%= simple_format @tour.tour_description %></div>
		</p>
		
    <p>活动由 <%= link_to @tour.participators.leader.login, user_url(@tour.participators.leader) %> 发起
		<% if @tour.editable_by?(current_user) -%>
			<%= link_to "编辑", edit_tour_url(@tour) %> | 
			<%= link_to "删除", tour_url(@tour), :method => :delete %>
		<% end -%></p>
		
		<div id="select-school">
		  <h3>旅途中要探访的学校</h3>
		  <p><span id="school-title"><%= @tour.school.blank? ? "还没有选择学校" : link_to(h(@tour.school.title), school_path(@tour.school.id)) %></span></p>
		  <% if @tour.editable_by?(current_user) -%>
		    <% form_for :tour, :url => tour_path(@tour), :html => {:method => 'put'} do |f| -%>
  		  <%= link_to_remote "选择学校", :url => {:controller => 'geo', :action => 'schools_list', :id => nil}, :before => "Element.hide('schools-list');Element.hide('schools-list-notice');Element.show('schools-list-spinner')" %>
  		  <div id="schools-list-spinner" style="display:none;color:gray">正在发送请求，请稍后 ...</div>
  		  <div id="schools-list-notice" style="display:none;color:gray"></div>
  		  <div id="schools-list" style="display:none"></div>
  		  <%= f.hidden_field :school_id %>
  		  <div id="schools-arrive-at" style="display:none">
  		    预计到达学校时间 <%= chinese_select_date "tour", "arrive_school_at" %> <%= submit_tag "确定" %>
  		  </div>
  		  <% end -%>
  		<% end -%>
		</div>
		
    <div id="participators">
  		<h3>同行的朋友</h3>
  		<% for p in @tour.participations -%>
  			<p><%= link_to p.user.login, user_url(p.user.id) %> 于 <%= show_date p.created_at %> 加入队伍</p>
  		<% end -%>
  		<br />
  		<% if @tour.participators.leader != current_user -%>
  			<% if @tour.participators.include?(current_user) -%>
  				我已经加入同行，<%= link_to "退出同行", quit_tour_url(@tour), :method => :put %>
  			<% else -%>
  				还等什么？<%= link_to "加入同行", join_tour_url(@tour), :method => :put %>
  			<% end -%>
  		<% end -%>
  	</div>
  </div>
</div>
<script type="text/javascript">
function select_school(id, title) {
  $('tour_school_id').value = id;
  $('school-title').innerHTML = "您选了" + title;
  Element.hide('schools-list');
  Element.hide('schools-list-spinner');
  Element.show('schools-arrive-at');
}
</script>